package online.indigo6a.tryspringcloudsecurity.controller;

import online.indigo6a.tryspringcloudsecurity.model.Articles;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import static org.apache.commons.lang3.RandomStringUtils.randomNumeric;

@RestController
@RequestMapping("/articles")
public class ArticlesController {

    private Logger logger = LoggerFactory.getLogger(ArticlesController.class);
    @GetMapping("/{id}")
    public Articles findOne(@PathVariable Long id) {
        return new Articles(Long.parseLong(randomNumeric(2)),randomAlphabetic(4));
    }
    @GetMapping
    public String[] findAll() {
        String[] articles = new String[] {
                randomAlphabetic(4), randomAlphabetic(4)
        };

        return articles;
    }
    @ResponseStatus(HttpStatus.CREATED)
    @PostMapping
    public void create(@RequestBody Articles newArticles) {
        logger.info("Created");
    }

}
